<?php include "include/function_library.php"; ?>
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>

<?php include "html/header.html"; ?>

</head>
<body class="tcuk home">

	<div id="wp">
	
		<?php  include "html/menu.html"; ?>
		
		<!-- CONTENT STARTS-->
		<div id="ct"> 	
			
			<?php 
			/* SIGN UP FORM PHP PART */
			if(post("hotel_submit")) {
				$hotel_name 		= post("hotel_name");
				$hotel_tel 			= post("hotel_tel");
				$hotel_capacity 	= post("hotel_capacity");
				$hotel_type 		= post("hotel_type");
				$hotel_price 		= post("hotel_price");
				$hotel_description	= post("hotel_description");
				
				$address_city		= post("address_city");
				$address_district	= post("address_district");
				$address_detail		= post("address_detail");
				
				$link = connect();
				$add_address_query = "INSERT INTO address (city, district, detail)
											VALUES ('$address_city', '$address_district', '$address_detail')";
				
				$result_address = mysql_query($add_address_query, $link) or die("Sql Error! " . mysql_error());
				$last_added_address_id = mysql_insert_id();
				
				$query = "INSERT INTO hotel (name, tel, capacity, type, price, description, address_id) 
									VALUES ('$hotel_name', '$hotel_tel', '$hotel_capacity', '$hotel_type', '$hotel_price', '$hotel_description', '$last_added_address_id')";
				$result = $result_address && (mysql_query($query, $link) or die("Sql Error! " . mysql_error()));
				mysql_close($link);
				
				if($result) {
					echo "<div class='alert success'>Hotel Saved Successfully! You can <a href='hotel_list.php'>take a look </a>at hotel list.</div>";
				} else {
					echo "<div class='alert error'>Error! Could Not Save! There is(are) error(s) in the form!</div>";
				}
			}
			?>
			<br/><h2>Add Hotel</h2>
			<!-- SIGN UP FORM HTML PART -->
			<form action="<?php echo curPageURL(); ?>" method="post">
			<ul id="signup_form" style="width: 50%; margin-left: auto; margin-right: auto; margin-top: 30px; list-style: none;">
				<li style="border: none;">
					<label>Name </label>
					<input type="text" id="hotel_name" name="hotel_name" value="" placeholder="Hotel name.." style="width: 250px;"/>
				</li>
				<li>
					<label>Phone </label>
					<input type="text" id="hotel_tel" name="hotel_tel" value="" placeholder="Hotel Phone.." style="width: 250px;"/>
				</li>
				<li>
					<label>Capacity </label>
					<input type="number" id="hotel_capacity" name="hotel_capacity" value="" placeholder="Hotel Capacity.." style="width: 250px;"/>
				</li>
				<li>
					<label>Type </label>
					<select id="hotel_type" name="hotel_type">
						<option value="Small hotel">Small hotel</option>
						<option value="Medium sized hotel">Medium sized hotel</option>
						<option value="Large hotel">Large hotel</option>
						<option value="Mega hotel">Mega hotel</option>
						<option value="Chain hotel">Chain hotel</option>
					</select>
				</li>
				<li>
					<label>Price</label>
					<input type="number" id="hotel_price" name="hotel_price" value="" placeholder="Price.." style="width: 120px;"/>
				</li>
				<li>
					<label>Description </label>
					<textarea rows="10" id="hotel_description" name="hotel_description" placeholder="Description.." style="width: 250px;"></textarea>
				</li>
				<li>
					<label>City </label>
					<input type="text" id="address_city" name="address_city" value="" placeholder="Hotel City.." style="width: 250px;"/>
				</li>
				<li>
					<label>District </label>
					<input type="text" id="address_district" name="address_district" value="" placeholder="Hotel District.." style="width: 250px;"/>
				</li>
				<li>
					<label>Address Detail </label>
					<textarea rows="10" id="address_detail" name="address_detail" placeholder="Address Detail.." style="width: 250px;"></textarea>
				</li>
				<li>
					<input type="submit" id="hotel_submit" name="hotel_submit" value="Save" style="width: 90px; height:30px; margin-left: 80px;"/>
				</li>
			</ul>
			</form>
		
		</div> 	
		<!-- CONTENT ENDS-->		
		
		<?php include "html/footer.html"; ?>
		
	</div>
	
</body>
</html>